package com.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.fh.modules.ums.entity.UmsMemberReceiveAddress;
import com.fhMall.request.QueryMemberAddressListRequest;
import com.wechat.feign.FhEmalMemberAddressApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author
 * @date 2019-09-18 20:00:31
 */
@RestController
@RequestMapping("wechat/userAddress")
@Api(tags = "")
public class WechatUserAddressController extends BaseController{

    @Autowired
    private FhEmalMemberAddressApi fhEmalMemberAddressApi;

    @ApiOperation(value = "地址列表")
    @GetMapping(value = "/queryMemberAddressList")
    public JSONObject queryMemberAddressList() {
        String result = fhEmalMemberAddressApi.queryMemberAddressList(this.getUserId());
        return JSONObject.parseObject(result);
    }

    /**
     * 详情
     * @param id
     * @return
    */
    @ApiOperation("详情")
    @GetMapping("/detail")
    public JSONObject details(@RequestParam(name="id") Integer id) {
        String result = fhEmalMemberAddressApi.queryMemberAddressInfo(id);
        return JSONObject.parseObject(result);
    }

    /**
     * 添加收货地址
     * @return
     * */
    @ApiOperation("添加收货地址")
    @PostMapping("/save")
    public JSONObject save(@RequestBody UmsMemberReceiveAddress umsMemberReceiveAddress) {
        umsMemberReceiveAddress.setMemberId(this.getUserId());
        String result = fhEmalMemberAddressApi.saveMemberAddress(umsMemberReceiveAddress);
        return JSONObject.parseObject(result);
    }

    /**
    * 修改
    * @param jsonObject
    * @return
    * */
    @ApiOperation("修改收货地址")
    @PutMapping("/update")
    public JSONObject update(@RequestBody JSONObject jsonObject) {
        String result = fhEmalMemberAddressApi.putMemberAddress(jsonObject);
        return JSONObject.parseObject(result);
    }

    /**
     * 删除收货地址
     * @param id
     * @return
     * */
    @ApiOperation("删除收货地址")
    @DeleteMapping("/delete")
    public JSONObject update(@RequestParam(name="id") String id) {
        String result = fhEmalMemberAddressApi.deleteMemberAddress(id);
        return JSONObject.parseObject(result);
    }
}
